var BASE_URL="http://api.gaoweizhou.com.cn/";
var UPLOAD_URL='//uploads.gaoweizhou.com.cn';
$(function(){ 
	//文字性接口
	$.ajax({
		  type : 'GET',
		  url: BASE_URL+"storage/"+'personal_profile',
		  success: function(result){
			  $(".introduction").html(result.data.value)
		  }
	});
	
	$.ajax({
		  type : 'GET',
		  url: BASE_URL+"storage/"+'art_road',
		  success: function(result){
			  $(".item-3-text").html(result.data.value)
		  }
	});
	//图片接口
	$.ajax({
		  type: 'GET',
		  url: BASE_URL+"picture/all",
		  success: function(result){
			  var painting = ''; //国画
			  var calligraphy = ''; //书法
			  var calligraphyCount = 0;
			  var paintingCount = 0;
			  result.data.forEach(function(item, index){
			  	if(item.pictureType == 'TRADITIONAL_CHINESE_PAINTING'){
			  		painting += formatTemplate(item);
			  		calligraphyCount += 1;
			  	}
			  	if(item.pictureType == 'CALLIGRAPHY'){
			  		calligraphy += formatTemplate(item);
			  		paintingCount += 1;
			  	}
			  })
			  $('#swiperWrap').html(painting)
			  $('#swiperWrap2').html(calligraphy)
			  createSwiper('.swiper-container1', calligraphyCount, 1)
			  createSwiper('.swiper-container2', paintingCount, 2)
		  }
	});

	function formatTemplate(item){
	  var url = UPLOAD_URL +item.pictureURL;
	  return '<div class="swiper-slide" data-src="'+url+'">'+
              '<div class="swiper-content file_img" style="background-image: url(' + url + ');">' + item.pictureName + '</div>'+
              '<div class="swiper-shadow">'+item.pictureName+'</div>'+
          '</div>';
	}
	function createSwiper(dom,perView, domIndex){
		return new Swiper(dom, {
			      slidesPerView: perView < 4 ? 1 : 4,
			      spaceBetween: 30,
			      autoHeight: true,
			      loop: true,
			      autoplay: {
			        delay: 5000,
			        stopOnLastSlide: false,
			        disableOnInteraction: false,
			        },
			      navigation: {
			        nextEl: '.swiper-button-next' + domIndex,
			        prevEl: '.swiper-button-prev' + domIndex,
			      },
			    });
	}
	$(document).on('click','.swiper-slide',function(){
		var src = $(this).data('src');
		showBigImg(src)
	})
	$(document).on('click','.shadow',function(e){
		var className = $(e.target).prop('className');
		if(className == 'shadow'){
			$('.shadow').remove()
		}
	})
	function showBigImg(imgSrc){
		var dom = '<div class="shadow" style="position:fixed;width:100%;height:100%;background-color:rgba(0,0,0,.4);z-index:999;top:0;left:0;"><div style="position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);"><img style="max-width:700px;" src="'+imgSrc+'" alt="" /></div></div>'
		$('body').append(dom)
	}

	$.ajax({
		type: 'GET',
	  	url: BASE_URL + "literaryWorks/all",
	  	success: function(data){
	  		var list = data.data;
	  		var str = '';
	  		list.forEach(function(item, index){
	  			str += '<li class="wenxue-li"><a href="'+item.jumpUrl+'" target="_blank" title="'+item.title+'">'+item.title+'</a></li>'
	  		})
	  		$('#wenxue').html(str)
	  	}
	})
}); 